absent_frequency_compliers <- ols_main(
	outcome = "absent_frequency",
	treatment = "absenteeism",
	resample_FE = TRUE,
	block_FE = TRUE,
	audience_size = TRUE,
	cluster_SE = TRUE,
	covariates = NULL,
	the_data = subset(el, respondent_category == "Complier"), 
	dosage = FALSE,
	dosage_indicator = FALSE)

absent_frequency_compliers_pvals <- get_RI_pvals(
	outcome = "absent_frequency",
	treatment = "absenteeism",
	resample_FE = TRUE,
	block_FE = TRUE,
	audience_size = TRUE,
	cluster_SE = TRUE,
	covariates = NULL,
	the_data = subset(el, respondent_category == "Complier"), 
	dosage = FALSE,
	dosage_indicator = FALSE,
	assignment_data = treatment_assignment,
	extract_function = coef,
	analysis_function = ols_main,
	sims = sims,
	lwr_upr_two = "two") #as per PAP.

# absent_frequency - never-takers
absent_frequency_nevertakers <- ols_main(
	outcome = "absent_frequency",
	treatment = "absenteeism",
	resample_FE = TRUE,
	block_FE = TRUE,
	audience_size = TRUE,
	cluster_SE = TRUE,
	covariates = NULL,
	the_data = subset(el, complier == FALSE), 
	dosage = FALSE,
	dosage_indicator = FALSE)

absent_frequency_nevertakers_pvals <- get_RI_pvals(
	outcome = "absent_frequency",
	treatment = "absenteeism",
	resample_FE = TRUE,
	block_FE = TRUE,
	audience_size = TRUE,
	cluster_SE = TRUE,
	covariates = NULL,
	the_data = subset(el, complier == FALSE), 
	dosage = FALSE,
	dosage_indicator = FALSE,
	assignment_data = treatment_assignment,
	extract_function = coef,
	analysis_function = ols_main,
	sims = sims,
	lwr_upr_two = "lwr") #as per PAP.



vht_village_level_ml <- 
	vht_ml %>% 
	group_by(tc_id,block_id,absenteeism) %>% 
	summarize(
		complain_absenteeism_ml = mean(complain_absenteeism,na.rm = T),
		radius = unique(radius),
		n_end_mean = unique(n_end_mean)
	)

vht_village_level_ml$tc <- vht_village_level_ml$tc_id

vht_village_level_el <- 
	vht_el %>% 
	group_by(tc_id,block_id,absenteeism) %>% 
	summarize(
		complain_absenteeism_el = mean(complain_absenteeism,na.rm = T),
		radius = unique(radius),
		n_end_mean = unique(n_end_mean)
	)
vht_village_level_el$tc <- vht_village_level_el$tc_id


# complain_absenteeism

complain_absenteeism_ml <- lm(
	complain_absenteeism_ml ~ absenteeism + as.factor(block_id) + n_end_mean, 
	data = vht_village_level_ml
)
complain_absenteeism_ml_pvals <- get_RI_pvals(
	outcome = "complain_absenteeism_ml",
	treatment = "absenteeism",
	resample_FE = F,
	block_FE = TRUE,
	audience_size = T,
	cluster_SE = F,
	covariates = NULL,
	the_data = vht_village_level_ml,
	assignment_data = treatment_assignment,
	sims = sims,
	lwr_upr_two = "two")

complain_absenteeism_el <- lm(
	complain_absenteeism_el ~ absenteeism + as.factor(block_id) + n_end_mean, 
	data = vht_village_level_el
)
complain_absenteeism_el_pvals <- get_RI_pvals(
	outcome = "complain_absenteeism_el",
	treatment = "absenteeism",
	resample_FE = F,
	block_FE = TRUE,
	audience_size = T,
	cluster_SE = F,
	covariates = NULL,
	the_data = vht_village_level_el,
	assignment_data = treatment_assignment,
	sims = sims,
	lwr_upr_two = "two")

#setup
control_means <- with(
	el, 
	c(
		"Control Mean",
		round(mean(absent_frequency[absenteeism == 0 & respondent_category == "Complier"],na.rm = TRUE), 2),
		round(mean(absent_frequency[absenteeism == 0 & complier == FALSE],na.rm = TRUE), 2),
		round(mean(vht_village_level_ml$complain_absenteeism_ml[vht_village_level_ml$absenteeism == 0],na.rm = TRUE), 2),
		round(mean(vht_village_level_el$complain_absenteeism_el[vht_village_level_el$absenteeism == 0],na.rm = TRUE), 2)
	)
)

pval_lines <- c(
	"RI $p$-values",
	round(absent_frequency_compliers_pvals$ri_pvals["absenteeism"],3),
	round(absent_frequency_nevertakers_pvals$ri_pvals["absenteeism"],3),
	round(complain_absenteeism_ml_pvals$ri_pvals["absenteeism"],3),
	round(complain_absenteeism_el_pvals$ri_pvals["absenteeism"],3)
)

hypothesis_lines <- c(
	"Hypothesis",
	"two",
	"lwr",
	"two",
	"two"
)

#make tables
sink("03_tables/ABS_behavior.tex")
stargazer(
	... = list(
		absent_frequency_compliers$fit,
		absent_frequency_nevertakers$fit,
		complain_absenteeism_ml,
		complain_absenteeism_el
	),
	type = "latex",
	p = list(
		absent_frequency_compliers_pvals$ri_pvals,
		absent_frequency_nevertakers_pvals$ri_pvals,
		complain_absenteeism_ml_pvals$ri_pvals,
		complain_absenteeism_el_pvals$ri_pvals
	),
	se = list(
		absent_frequency_compliers$fit_summary[,"Std. Error"],
		absent_frequency_nevertakers$fit_summary[,"Std. Error"],
		summary(complain_absenteeism_ml)$coefficients[, "Std. Error"],
		summary(complain_absenteeism_el)$coefficients[, "Std. Error"]
	),
	
	keep = "absenteeism",
	omit.stat = c("rsq","f","ser"),
	column.separate = c(2,2),
	column.labels = c("Reported absenteeism","Parents complain"),
	table.layout = "=cd#-t-as=n",
	dep.var.labels = c("Endline","Midline","Endline"),
	dep.var.labels.include = TRUE,
	no.space = T,
	omit = "block_id",
	add.lines = list(
		control_means,
		pval_lines,
		hypothesis_lines,
		c("Block FE",
			"Yes","Yes","Yes","Yes"),
		c("Sample", "Compl.", "Never-T","VHT","VHT"),
		c("Analysis Level", "Indiv.", "Indiv.", "Clus.", "Clus.")),
	notes.label = "",
	float = FALSE
	# style = "qje"
)
sink()
